<template>
    <div class="products-container">
        <div class="ModuleImageTextGiantContent ModuleImageTextContent">
            <p><span class="title-blue-line">|</span><span class="title-main">产品列表 <span class="title-sub">/ Product
                        Display</span></span></p>
        </div>

        <div class="product-index">
            <div class="index-grid">
                <div v-for="product in products" :key="product.id" class="index-item"
                    @click="scrollToProduct(product.id)">
                    <div class="index-icon">
                        <img :src="product.icon" :alt="product.name">
                    </div>
                    <h3>{{ product.name }}</h3>
                </div>
            </div>
        </div>

        <div class="ModuleImageTextGiantContent ModuleImageTextContent">
            <p><span class="title-blue-line">|</span><span class="title-main">服务对象 <span class="title-sub">/ Service
                        Target</span></span></p>
        </div>

        <!-- 新增服务对象区块 -->
        <div class="service-targets">
            <div class="target-grid">
                <div v-for="(target, index) in serviceTargets" :key="index" class="target-item">
                    <div class="target-icon">
                        <img :src="`/img4s/K${index + 1}.png`" :alt="target">
                    </div>
                    <h3>{{ target }}</h3>
                </div>
            </div>
        </div>

        <div class="ModuleImageTextGiantContent ModuleImageTextContent">
            <p><span class="title-blue-line">|</span><span class="title-main">八大优势 <span class="title-sub">/ Eight
                        Advantage</span></span></p>
        </div>
        <!-- 修改后的公司优势区块 -->
        <div class="company-advantages">
            <div class="advantage-spider">
                <div class="spider-center">
                    <div class="center-text">新鹏原电子<br>八大优势</div>
                </div>
                <div v-for="(item, index) in advantages" :key="index" class="spider-item"
                    :style="getSpiderPosition(index)">
                    <div class="spider-icon">{{ index + 1 }}</div>
                    <div class="spider-content">{{ item }}</div>
                </div>
            </div>
        </div>

        <!-- 新增双Tab页 -->
        <div class="ModuleImageTextGiantContent ModuleImageTextContent">
            <p><span class="title-blue-line">|</span><span class="title-main">品牌与伙伴 <span class="title-sub">/ Brands &
                        Partners</span></span></p>
        </div>

        <div class="tab-container">
            <div class="tab-header">
                <button @click="activeTab = 'brands'" :class="{ active: activeTab === 'brands' }">
                    代理品牌
                </button>
                <button @click="activeTab = 'partners'" :class="{ active: activeTab === 'partners' }">
                    合作伙伴
                </button>
            </div>

            <div class="tab-content">
                <div v-show="activeTab === 'brands'" class="tab-panel">
                    <div class="brand-grid">
                        <div v-for="(brand, index) in brands" :key="index" class="brand-item">
                            <img :src="`/images/brand-${index+1}.png`" :alt="brand">
                        </div>
                    </div>
                </div>

                <div v-show="activeTab === 'partners'" class="tab-panel">
                    <div class="partner-grid">
                        <div v-for="(partner, index) in partners" :key="index" class="partner-item">
                            <img :src="`/images/partner-${index+1}.png`" :alt="partner">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import product from "../js/products";

export default {
    name: 'Products',
    data() {
        return {
            serviceTargets: [
                '电焊机',
                '变频器',
                'UPS不间断电源',
                '光伏新能源',
                '逆变器',
                '开关电源',
                'MPPTO',
                '通讯电源',
                '小家电',
                '安防行业',
                '仪器仪表'
            ],
            advantages: [
                '产品线资源丰富，实现客户One stop shopping节省人力成本',
                '多重品牌，更能掌握全盘供需局势，提供建议或替代料',
                '强到系统管理进销存，交货灵活，深圳，香港均可以交货',
                '与欧美，日本，台湾品牌合作，并确保货物原装正品',
                '销售市场咨询，定期将行业咨询分享给客户',
                '针对不同产业，提供专业技术支持',
                '拥有专业团队，70%以上从业人员都是业内精英，行业经验超过10年',
                '行业内有足够价格合作优势'
            ],
            products: product,
            activeTab: 'brands',
            brands: [
                'Daili'
            ],
            partners: [
                '合作伙伴1'
            ]
        }
    },
    methods: {
        scrollToProduct(id) {
            const element = document.getElementById(id);
            if (element) {
                element.scrollIntoView({ behavior: 'smooth' });
            }
        },
        
        getSpiderPosition(index) {
            const angle = [-90, -25, 0, 35, 90, 140, 170,200][index];
            const radius = [200, 250, 350, 250, 250, 250, 350, 300][index];
            return {
                left: `calc(50% + ${radius * Math.cos(angle * Math.PI / 180)}px)`,
                top: `calc(50% + ${radius * Math.sin(angle * Math.PI / 180)}px)`
            };
        }
    }
}
</script>

<style scoped>
.products-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
    color: #2c3e50;
    margin-bottom: 40px;
}

/* 产品索引区样式 */
.product-index {
    margin-bottom: 50px;
    padding: 20px;
    background: #f5f7fa;
    border-radius: 8px;
}

.index-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.index-item {
    background: white;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.index-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.index-icon img {
    width: 50px;
    height: 50px;
    object-fit: contain;
}

/* 产品详情区样式 */
.product-section {
    margin-bottom: 60px;
    padding-bottom: 30px;
    border-bottom: 1px solid #eee;
}

.product-content {
    display: flex;
    gap: 30px;
    margin-top: 20px;
}

.product-image {
    width: 300px;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
}

.product-info {
    flex: 1;
}

.specs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 10px;
}

.spec-item {
    background: #f8f9fa;
    padding: 8px 12px;
    border-radius: 4px;
}

.spec-key {
    font-weight: bold;
    margin-right: 5px;
}

/* 新增服务对象样式 */
.service-targets {
    margin-bottom: 50px;
    padding: 30px;
    background: #f8fafc;
    border-radius: 12px;
}

.service-targets h2 {
    text-align: center;
    color: #1976d2;
    margin-bottom: 30px;
    font-size: 1.5rem;
}

.target-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 25px;
}

.target-item {
    background: white;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
}

.target-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.target-icon img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    margin-bottom: 15px;
}

.target-item h3 {
    color: #2c3e50;
    font-size: 1rem;
    margin-top: 10px;
}

.ModuleImageTextGiantContent {
    text-align: left;
    margin-bottom: 30px;
}

.title-blue-line {
    color: rgb(84, 141, 212);
    font-size: 28px;
    font-weight: bold;
    margin-right: 10px;
}

.title-main {
    color: rgb(12, 12, 12);
    font-size: 28px;
    font-weight: normal;
}

.title-sub {
    color: rgb(12, 12, 12);
    font-size: 14px;
    margin-left: 5px;
}

/* 修改后的公司优势样式 */
.company-advantages {
    margin: 50px 0;
    padding: 30px;
    background: #f5f9ff;
    border-radius: 12px;
    position: relative;
    height: 600px; /* 增加高度 */
}

.advantage-spider {
    position: relative;
    height: 100%;
}

.spider-center {
    position: absolute;
    width: 180px; /* 增大中心圆 */
    height: 180px;
    background: #1976d2;
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}

.spider-item {
    position: absolute;
    width: 240px; /* 增加宽度 */
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
}

.spider-icon {
    width: 40px;
    height: 40px;
    background: #1976d2;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-right: 15px;
    flex-shrink: 0;
}

.spider-content {
    background: white;
    padding: 12px 15px;
    border-radius: 8px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
    font-size: 14px;
    line-height: 1.5;
    min-width: 180px; /* 设置最小宽度 */
}

/* 新增Tab页样式 */
.tab-container {
    margin: 50px 0;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.tab-header {
    display: flex;
    border-bottom: 1px solid #eee;
}

.tab-header button {
    flex: 1;
    padding: 15px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    color: #666;
    transition: all 0.3s;
}

.tab-header button.active {
    color: #1976d2;
    font-weight: bold;
    border-bottom: 2px solid #1976d2;
}

.tab-content {
    padding: 20px;
}

.brand-grid, .partner-grid {
    display: block;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
    align-items: center;
}

.brand-item img, .partner-item img {
    max-width: 100%;
    height: auto;
    filter: grayscale(30%);
    transition: all 0.3s;
}

.brand-item:hover img, .partner-item:hover img {
    filter: grayscale(0%);
    transform: scale(1.05);
}
</style>